package com.itheima.dao.impl;

import com.alibaba.druid.pool.DruidDataSource;
import com.itheima.dao.UserDao;
import com.itheima.utils.Myutils;
import org.apache.commons.dbutils.QueryRunner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.Connection;
import java.sql.SQLException;


@Repository//Daoceng 的注解名字  把这个类加载到ioc容器中
public class UserDaoImpl implements UserDao {

    @Autowired
    private QueryRunner queryRunner;



    @Override
    public void jianqian(Integer money, String outname, String inname) {

        try {
            String sql = "update account set money = money-? where name=?";
            //减=钱
            queryRunner.update(sql,money,outname);
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("加钱时出错了");
        }
    }

    @Override
    public void jiaqian(Integer money, String outname, String inname) {
        try {
            String sqladd = "update account set money = money+? where name=?";
            //加钱
            queryRunner.update(sqladd,money,inname);
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }

    @Override
    public void saveMoney(String name,Integer money) {


        try {
            String sqlsave = "update account set money = money+? where name=?";
            //加钱
            queryRunner.update(sqlsave,money,name);
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
